package pers.zw.service.impl;

import pers.zw.dao.IUserDao;
import pers.zw.dao.impl.UserDaoImpl;
import pers.zw.domain.User;
import pers.zw.exception.UserExistException;
import pers.zw.service.IUserService;

public class UserServiceImpl implements IUserService {

    private final IUserDao userDao = new UserDaoImpl();

    @Override
    public void registerUser(User user) throws UserExistException {
        if (userDao.find(user.getUserName()) != null) {
            throw new UserExistException("User exists!");
        }
        userDao.add(user);
    }

    @Override
    public User loginUser(String userName, String userPwd) {
        return userDao.find(userName, userPwd);
    }
}
